<template>
  <div id="login">
    <form>
      <label for="userName">用户名</label><input type="text" v-model="userName" name="userName" />
      <label for="password">密码</label><input type="password" v-model="password" name="password"/>
      <input type="button" value="登录" @click="doLogin"/>
    </form>
  </div>
</template>

<script>
  import qs from 'qs'
  export default {
    name: 'login',
    data () {
      return {
        userName: '',
        password: ''
      }
    },
    methods:{
      doLogin () {
        this.$axios.post('/login',
          qs.stringify({
            userName: this.userName,
            password: this.password,
          })
        )
          .then((response) => {
            console.log(response)
            sessionStorage.setItem('user', qs.stringify(response.data.result));
            sessionStorage.setItem('token', response.data.token);
            this.$router.replace({path: '/hello'})
         })
      }
    }
  }
</script>

